package com.sinopec.basemodule.adapter;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;

import java.util.List;

/**
 * @author lwj
 * @ClassName: CommonAdapter
 * @Description:通用適配器
 */
public abstract class CommonAdapter<T> extends MultiItemTypeAdapter<T> {
    protected Context mContext;
    protected int mLayoutId;
    protected LayoutInflater mInflater;

    public CommonAdapter(final Context context, final int layoutId, List<T> datas) {
        super(context, datas);
        mContext = context;
        mInflater = LayoutInflater.from(context);
        mLayoutId = layoutId;
        mDatas = datas;

        addItemViewDelegate(new ItemViewDelegate<T>() {
            @Override
            public int getItemViewLayoutId() {
                return layoutId;
            }

            @Override
            public boolean isForViewType(T item, int position) {
                return true;
            }

            @Override
            public void convert(CustomViewHolder holder, T t, int position) {
                Log.d("sglei-refresh", "convert");
                CommonAdapter.this.convert(holder, t, position);
            }

            @Override
            public void convert(CustomViewHolder holder, T t, int position, List<Object> payloads) {
                CommonAdapter.this.convert(holder, t, position, payloads);
            }
        });
    }

    public abstract void convert(CustomViewHolder holder, T t, int position);

    public void convert(CustomViewHolder holder, T t, int position, List<Object> payloads) {
    }

    public void setData(List<T> newData) {
        mDatas = newData;
    }
}
